package com.xebia.eshop.services.books.impl;

import java.util.Collection;
import java.util.List;
import java.util.Set;

import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.core.MediaType;

import org.apache.commons.collections.CollectionUtils;

import com.sun.jersey.api.client.GenericType;
import com.sun.jersey.api.client.WebResource;
import com.xebia.eshop.beans.books.Book;
import com.xebia.eshop.services.books.BookService;
import com.xebia.eshop.utils.jsonclient.JSonClient;

public class BookServiceImpl implements BookService{
	@Inject
	@Named("test") 
	private String TESsdfsdf;
	

	
	@Override
	public String getBooksList() {
		WebResource webResource = JSonClient.CLIENT.resource("http://henri-potier.xebia.fr/books");
		webResource.accept(MediaType.APPLICATION_JSON);
		for (Book book : webResource.get(new GenericType<List<Book>>(){})) {
			System.out.println(book.getIsbn());
		}
//		System.out.println(booklist);
		System.out.println(TESsdfsdf);
		return null;
	}

	@Override
	public boolean booksExist(Collection<Book> booksToCheck) {
		WebResource webResource = JSonClient.CLIENT.resource("http://henri-potier.xebia.fr/books");
		webResource.accept(MediaType.APPLICATION_JSON);
		Set<Book> books = webResource.get(new GenericType<Set<Book>>(){});
		return CollectionUtils.isNotEmpty(books) && books.containsAll(booksToCheck);
	}
	
	
}
